package com.gisterrier.server.db;

import java.sql.ResultSet;

import com.common.db.DBClassMapping;
import com.gisterrier.shared.BuildingCustomerShort;
import com.gisterrier.shared.Customer;
import com.gisterrier.shared.GIsMap_SocarNet;
import com.gisterrier.shared.Map_Customer_to_Building;
import com.gisterrier.shared.Map_Customer_to_Network;
import com.gisterrier.shared.Map_Street_to_Street;
import com.gisterrier.shared.ObjSelectionresult;

public class DBMapping {

	public static Customer getCustomer(ResultSet rs) throws Exception {
		Customer result = new Customer();

		result.setCusid(rs.getInt("cusid"));
		result.setStreetid(rs.getInt("streetid"));
		result.setCustypeid(rs.getInt("custypeid"));
		result.setCusname(rs.getString("cusname"));
		result.setFlat(rs.getString("flat"));
		result.setHome(rs.getString("home"));
		result.setHometypeid(rs.getInt("hometypeid"));
		result.setJob(rs.getString("job"));
		result.setNdoc(rs.getLong("ndoc"));
		result.setPhone(rs.getString("phone"));
		result.setStartamount(rs.getDouble("startamount"));
		result.setStartdate(rs.getTimestamp("startdate"));
		result.setUserr(rs.getString("userr"));

		result.setCusstatusid(rs.getInt("cusstatusid"));
		result.setClassid(rs.getInt("classid"));
		result.setScope_id(rs.getInt("scope_id"));
		result.setGasspressid(rs.getInt("gasspressid"));
		result.setBusiness_id(rs.getInt("business_id"));

		result.setPrivate_number(rs.getString("private_number"));
		result.setCus_inn(rs.getString("cus_inn"));

		return result;
	}

	public static Map_Street_to_Street getMap_Street_to_Street(ResultSet rs)
			throws Exception {
		Map_Street_to_Street result = new Map_Street_to_Street();

		result.setId(rs.getLong("id"));
		result.setMap_street_id(rs.getLong("map_street_id"));
		result.setBilling_street_id(rs.getLong("billing_street_id"));
		result.setStreetname(rs.getString("streetname"));
		result.setCityid(rs.getLong("cityid"));
		result.setSubregionid(rs.getLong("subregionid"));
		result.setRegion(rs.getLong("region"));

		return result;
	}

	public static Map_Customer_to_Building getMap_Customer_to_Building(
			ResultSet rs) throws Exception {
		Map_Customer_to_Building result = new Map_Customer_to_Building();

		result.setId(rs.getLong("id"));
		result.setCus_id(rs.getLong("cus_id"));
		result.setBuilding_id(rs.getLong("building_id"));
		result.setCustname(rs.getString("custname"));
		return result;
	}

	public static Map_Customer_to_Network getMap_Customer_to_Network(
			ResultSet rs) throws Exception {
		Map_Customer_to_Network result = new Map_Customer_to_Network();

		result.setId(rs.getLong("id"));
		result.setCus_id(rs.getLong("cust_id"));
		result.setTube_id(rs.getLong("tube_id"));
		result.setCustname(rs.getString("custname"));
		return result;
	}

	public static ObjSelectionresult getObjSelectionresult(ResultSet rs)
			throws Exception {
		ObjSelectionresult result = new ObjSelectionresult();
		result.setRaioni(rs.getLong("raioni"));
		result.setRegioni(rs.getLong("regioni"));
		result.setCityid(rs.getLong("cityid"));
		result.setStreetid(rs.getLong("streetid"));
		return result;
	}

	public static GIsMap_SocarNet getGIsMap_SocarNet(ResultSet rs)
			throws Exception {
		GIsMap_SocarNet result = new GIsMap_SocarNet();
		DBClassMapping.setGisMap_Roads(result, rs);
		result.setObjekt_id(rs.getString("objekt_id"));
		return result;
	}

	public static BuildingCustomerShort getBuildingCustomerShort(ResultSet rs)
			throws Exception {
		BuildingCustomerShort result = new BuildingCustomerShort();
		result.setCusid(rs.getLong("cusid"));
		result.setCusname(rs.getString("cusname"));
		result.setBuilding_id(rs.getLong("building_id"));
		result.setStreetid(rs.getLong("streetid"));
		return result;
	}
}
